package com.tsingteng.cosfun.ui.setting;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tsingteng.cosfun.MainActivity;
import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.base.BaseFragment;
import com.tsingteng.cosfun.callback.AppListener;
import com.tsingteng.cosfun.common.Constant;
import com.tsingteng.cosfun.common.Navigate;
import com.tsingteng.cosfun.ui.login.LogonAgreementFragment;
import com.tsingteng.cosfun.ui.message.fans.model.IFansListModel;
import com.tsingteng.cosfun.ui.message.geneal.PlayDetailFragment;
import com.tsingteng.cosfun.ui.mine.DraftsFragment;
import com.tsingteng.cosfun.ui.mine.HomeMineFragment;
import com.tsingteng.cosfun.ui.mine.TerminalActivity;
import com.tsingteng.cosfun.utils.AppUtils;
import com.tsingteng.cosfun.utils.DataClearManager;
import com.tsingteng.cosfun.utils.LogUtils;
import com.tsingteng.cosfun.utils.LogonUtils;
import com.tsingteng.cosfun.utils.NotchUtil;
import com.tsingteng.cosfun.utils.ToastUtils;
import com.tsingteng.cosfun.widget.TitleView;
import com.tsingteng.cosfun.widget.dialog.ContentDialog;

/**
 * author :zhikuan
 * Date:18-8-9
 */
public class HomeSettingFragment extends BaseFragment implements View.OnClickListener {

    private TextView cache;
    private RelativeLayout titleView;
    private ImageView ivLeft;

    @Override
    protected void initView() {

        cache = rootView.findViewById(R.id.cache);
        cache.setText(DataClearManager.getTotalCacheSize(getActivity()));
        rootView.findViewById(R.id.setting_about).setOnClickListener(this);
        rootView.findViewById(R.id.setting_feedback).setOnClickListener(this);
        rootView.findViewById(R.id.profile_adress).setOnClickListener(this);
        rootView.findViewById(R.id.account_manage).setOnClickListener(this);
        rootView.findViewById(R.id.setting_cache_clear).setOnClickListener(this);
        rootView.findViewById(R.id.setting_agement).setOnClickListener(this);
        rootView.findViewById(R.id.setting_intimate).setOnClickListener(this);
        rootView.findViewById(R.id.logout).setOnClickListener(this);
        titleView = rootView.findViewById(R.id.tv_title_view);
        View view = rootView.findViewById(R.id.view);
        if (NotchUtil.isAllScreenDevice(getActivity())){
            view.setVisibility(View.GONE);
        }else{
            view.setVisibility(View.VISIBLE);
        }

        ivLeft = rootView.findViewById(R.id.iv_left);
        ivLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });



    }

    @Override
    protected void getBundle(Bundle bundle) {

    }

    @Override
    public void onResume() {
        super.onResume();

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_setting_home_layout;
    }


    @Override
    public void onClick(View view) {
        Bundle bundle;
        switch (view.getId()) {
            case R.id.profile_adress:
                Navigate.gotoProfileAdress(getActivity());
                break;
            case R.id.setting_about:
                TerminalActivity.showFragment(getActivity(), AboutFragment.class, null);
                break;
            case R.id.setting_cache_clear:
                if (DataClearManager.clearAllCache(getActivity())) {
                    ToastUtils.showToast("清除缓存成功");
                    cache.setText(DataClearManager.getTotalCacheSize(getActivity()));
                }
                break;
            case R.id.setting_feedback:
                TerminalActivity.showFragment(getActivity(), FeedbackFragment.class, null);
                break;
            case R.id.account_manage:
                TerminalActivity.showFragment(getActivity(), AccountManageFragment.class, null);
                break;
            case R.id.setting_agement:
                 bundle= new Bundle();
                 bundle.putInt("agementType",1);
                TerminalActivity.showFragment(getActivity(), LogonAgreementFragment.class, bundle);
                break;
            case R.id.setting_intimate:
                bundle= new Bundle();
                bundle.putInt("agementType",2);
                TerminalActivity.showFragment(getActivity(), LogonAgreementFragment.class, bundle);
                break;

            case R.id.logout:
                if (LogonUtils.getIsLogin()) {
                    new ContentDialog(getContext()).setContent("退出登录?").setCancelContent("取消").setAffirmContent("退出").setAffirmContentColor(R.color.red_bag_color).setOnTwoClickListener(new ContentDialog.OnTwoClickListener() {
                        @Override
                        public void onAffirm() {
                            LogonUtils.outLogon();
                            HomeMineFragment.isOutLogon = true;
                            AppListener.OnRefreshBackListener onBackListener = AppListener.getInstance().getOnRefreshBackListener();
                            if (onBackListener!=null) {
                                onBackListener.OnReresh("");
                            }
                            getActivity().finish();

                        }

                        @Override
                        public void onCancel() {

                        }
                    }).show();

                }

                break;
        }
    }
}
